/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sunsite.action;

import com.opensymphony.xwork2.ActionSupport;
import java.util.Locale;
import org.springframework.context.support.ResourceBundleMessageSource;
import sunsite.service.UserService;
import sunsite.tools.Json;

/**
 *
 * @author Ruby
 */

public class CheckUser extends ActionSupport {

    //请求参数
    private String userName;
    
    //传递参数
    private String message;
    
    private UserService userService;
    private ResourceBundleMessageSource messageSource;
    
    public CheckUser() {
    }

    @Override
    public String execute() throws Exception {
        Json json = new Json();
        if(userService.isUserExisted(userName))
        {
            json.add(Json.Answer, 1);
            json.add(Json.MsgContent, messageSource.getMessage("user.userExist", null, Locale.getDefault()));
        }
        else
        {
            json.add(Json.Answer, 0);
            json.add(Json.MsgContent, messageSource.getMessage("user.userNotExist", null, Locale.getDefault()));
        }
        message = json.toString();
        
        return SUCCESS;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getMessage() {
        return message;
    }

    public void setMessageSource(ResourceBundleMessageSource messageSource) {
        this.messageSource = messageSource;
    }
}